package com.sucisoft.base.network.config;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 2033152950
 * Created by zf on 2018/5/7.
 */

public class NetC {
    /**
     * 配置url
     */
    public static final String BaseUrl = "http://192.168.1.208:8080/";

    private NetC() {
    }

    /**
     * new
     * @return
     */
    public static NetC newC() {
        return new NetC();
    }

    protected String Url = null;

    protected String FileKey = null;

    protected Object tag = null;

    protected Map<String, Object> map = new HashMap<>();

    protected List<File> files = new ArrayList<>();

    public String getUrl() {
        return Url;
    }

    /**
     * 地址
     * @param url
     * @return
     */
    public NetC Url(String url) {
        if (url.contains("http")) {
            this.Url = url;
        } else {
            this.Url = BaseUrl + url;
        }
        return this;
    }

    public Object getTag() {
        return tag;
    }

    /**
     * 标签
     * @param tag
     * @return
     */
    public NetC Tag(Object tag) {
        this.tag = tag;
        return this;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    /**
     * 参数
     * @param key
     * @param value
     * @return
     */
    public NetC addParams(String key, String value) {
        map.put(key, value);
        return this;
    }

    public List<File> getFile() {
        return files;
    }

    public Boolean IsFile() {
        return files.size() > 0;
    }

    public String getFileKey() {
        return FileKey;
    }

    /**
     * 上传文件对应的key 和 addFile addFiles成对使用
     * @param Key
     * @return
     */
    public NetC setFileKey(String Key) {
        FileKey = Key;
        return this;
    }

    /**
     * 单个文件
     *
     * @param file
     * @return
     */

    public NetC addFile(File file) {
        files.add(file);
        return this;
    }

    /**
     * 多个文件
     *
     * @param file
     * @return
     */
    public NetC addFiles(List<File> file) {
        files.addAll(file);
        return this;
    }
}
